package raojt.day0109.tour.utils;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class ConfigManager {
    private volatile static ConfigManager configManager;
    private static Properties properties;

    private ConfigManager(){
        String configPath = "database.properties";
        properties = new Properties();
        InputStream is = ConfigManager.class.getClassLoader().getResourceAsStream(configPath);
        try {
            properties.load(is);
        }catch (IOException e){
            e.printStackTrace();
        }finally {
            if (is != null){
                try {
                    is.close();
                }catch (IOException e){
                    e.printStackTrace();
                }
            }
        }
    }

    public static ConfigManager getInstance(){
        if (configManager == null){
            synchronized (ConfigManager.class){
                if (configManager == null){
                    configManager = new ConfigManager();
                }
            }
        }
        return configManager;
    }

    public String getProperty(String key){return properties.getProperty(key);}
}
